package ewu
import ewu._
import scala.collection.mutable.ArrayBuffer

/**
 * Diese Klasse erlaubt den Arrayzugriff ueber einen Indize
 * fuer den Fall das mit einem ArrayEnvironment gearbeitet wird.
 * *im ADAlyzer nicht verwendet
 */

case class ArrayValue(name: String,
                      pos:Int,
                      expr:Expression,
                      aenv:ArrayEnvironment) extends Operand {

  def this(name:String, pos:Int,aenv:ArrayEnvironment) =
    this(name,pos,null,aenv)

  def this(name:String,pos:Expression,aenv:ArrayEnvironment) =
    this(name,0,pos,aenv)

  def evaluate(env: Environment): Option[BigInt] =  {
    if(aenv == null)
      None
    else {
      aenv.getValue(name) match{
        case Some(array) =>
          if (expr == null) {
          Some(array.valueAt(pos))
        } else {
          Some(array.valueAt(expr,env))
        }
        case _ => None
      }
    }
  }

  override def toString: String = {
    if(pos == 0)
      return name+"("+expr.reduce+")"
    else
      return name+"("+pos+")"
  }

  def toAdaConstructor: String = ""

  def toAdaConstructor(t: Int): String = ""

  def toScalaConstructor: String = ""

  def toScalaConstructor(t: Int): String = ""
  
  def getVariables(a: ArrayBuffer[Name]) = {}
  def replaceVariable(fromVar: Name, toVar: Expression) = {}
}